/*
   Copyright 2011 Jason Drake (jadrake75@gmail.com)
 
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.javad.components;

import javax.swing.JPanel;
import java.awt.BorderLayout;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

@SuppressWarnings("serial")
public class IconLabel extends JPanel {
	private JLabel textLabel;
	private JLabel iconLabel;
	
	
	public IconLabel(String text, Icon icon) {
		initialize(text, icon);
	}
	private void initialize(String text, Icon icon) {
		setOpaque(false);
		setLayout(new BorderLayout(0, 0));
		getTextLabel().setText(text);
		getIconLabel().setIcon(icon);
		add(getTextLabel(), BorderLayout.SOUTH);
		add(getIconLabel(), BorderLayout.CENTER);
		
	}

	protected JLabel getTextLabel() {
		if (textLabel == null) {
			textLabel = new JLabel(""); //$NON-NLS-1$
			textLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return textLabel;
	}
	protected JLabel getIconLabel() {
		if (iconLabel == null) {
			iconLabel = new JLabel(""); //$NON-NLS-1$
			iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return iconLabel;
	}
	
	/** 
	 * Will set the text to appear for the label.
	 * 
	 * @param text
	 */
	public void setText(String text) {
		getTextLabel().setText(text);
	}
	
	/**
	 * Will retrieve the text used by the label.
	 * @return
	 */
	public String getText() {
		return getTextLabel().getText();
	}
	
	
	public void setIcon(Icon icon) {
		getIconLabel().setIcon(icon);
	}
	
	public Icon getIcon() {
		return getIconLabel().getIcon();
	}
}
